<?php
/**
 * 提货记录
 * (model)
 */
namespace App\Models\Shipping;

use App\Models\Basics\SysArea;
use App\Models\Product\ProductClassify;
use App\Models\Product\ProductSku;
use Illuminate\Database\Eloquent\Model;
class SSkuLog extends Model
{
    protected $table = 's_shipping_sku_log';

    protected $guarded = [];

    protected $casts = [
        'apply' => 'array',
    ];

    public function area(){
        return $this->belongsTo(SysArea::class,'area_id');
    }

    public function sku(){
        return $this->belongsTo(ProductSku::class,'psku_id');
    }

    public function skuClassify(){
        return $this->hasOneThrough(
            ProductClassify::class,
            ProductSku::class,
            'id',//中间表
            'id',//目标表
            'psku_id',//当前模型
            'classify_id'//中间表
        );
    }

    /**
     * 获取格式化的需求
     * @param $apply
     * @return string
     */
    public static function formatApply($apply){
        $re = [];
        foreach ($apply as $label => $item){
            $re[] = $label.':'.$item;
        }
        return implode('；',$re);
//        return implode('；',collect($apply)->map(function ($item, $key){
//            return $key.':'.$item;
//        })->toArray());
    }
}
